package com.fanshuai.springcloud.service;

import com.fanshuai.springcloud.domain.Book;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

public class BookService {
    List<Book> books = new ArrayList<>();

    public List<Book> list() {
        return books;
    }

    public Book get(long bookId) {
        return books.stream().filter(book -> {
            return book.getId() == bookId;
        }).findFirst().orElse(null);
    }

    public void add(Book book) {
        books.add(book);
    }

    public void delete(long bookId) {
        books = books.stream().filter(book -> {
            return book.getId() == bookId;
        }).collect(Collectors.toList());
    }
}
